﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Remp.Data.Repository
{
    public interface IObjectContext:IDisposable
    {
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity">待添加的实体实例</param>
        /// <returns>返回添加成功的实例</returns>
        /// <remarks>
        /// 返回的实体和传入的实例是同一个引用
        /// </remarks>
        T Add<T>(T entity) where T : class;

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">待更新的实例</param>
        void Update<T>(T entity) where T : class;

        /// <summary>
        /// 删除一个实例
        /// </summary>
        /// <param name="entity">待删除的实例</param>
        void Delete<T>(T entity) where T : class;

        /// <summary>
        /// 根据条件查询获取一个实例
        /// </summary>
        /// <param name="condition">查询条件</param>
        /// <returns>符合条件的实例</returns>
        T GetBy<T>(Func<T, bool> condition) where T : class;

        /// <summary>
        /// 提供数据源的查询进行计算的功能
        /// </summary>
        /// <returns>数据集的查询集</returns>
        IQueryable<T> CreateQuery<T>() where T : class;

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <returns></returns>
        IQueryable<T> CreateQuery<T>(string query) where T : class;

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="funName"></param>
        /// <param name="params"></param>
        /// <returns></returns>
        T ExecuteFunction<T>(string funName, params object[] @params);

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="funName"></param>
        /// <param name="params"></param>
        /// <returns></returns>
        T ExecuteStoreCommand<T>(string funName, params object[] @params);
    }
}
